package com.hongxun.budget.ui.fragment.ys;

import android.text.TextUtils;
import android.widget.TextView;

import com.hongxun.budget.R;
import com.hongxun.budget.greendao.EProblemexistEntityDao;
import com.hongxun.budget.ui.fragment.BaseListFragment;
import com.hongxun.budget.utils.DBUtils;
import com.hongxun.budget.utils.DateUtils;
import com.hongxun.budget.utils.GreenDaoManager;
import com.hongxun.budget.utils.SPUtils;
import com.hongxun.greenentity.ys.EProblemexistEntity;
import com.jessewu.library.SuperAdapter;
import com.jessewu.library.view.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2018/9/25.
 */

public class YsInfoFragment extends BaseListFragment {

    List<EProblemexistEntity> datas = new ArrayList<>();
    SuperAdapter<EProblemexistEntity> adapter;

    @Override
    public SuperAdapter getAdapter() {
        return adapter = new SuperAdapter<EProblemexistEntity>(R.layout.content_ys_info) {
            @Override
            public void bindView(ViewHolder viewHolder, final EProblemexistEntity e, int i) {
                ((TextView) viewHolder.getView(R.id.location)).setText(DBUtils.getYsLineNameAndPoint(e.getPointguid()));
                ((TextView) viewHolder.getView(R.id.process)).setText(TextUtils.isEmpty(e.getHandler()) ? "(未处理)" : "(已处理)");
                ((TextView) viewHolder.getView(R.id.problem)).setText(e.getCommon());
                ((TextView) viewHolder.getView(R.id.description)).setText(e.getAnalysis());
                ((TextView) viewHolder.getView(R.id.time)).setText(DateUtils.getDateToStringNoHH(e.getFindtime()));
                TextView textView = viewHolder.getView(R.id.ys);
                if (TextUtils.isEmpty(e.getAccepter())) {
                    textView.setTextColor(getResources().getColor(R.color.colorAccent));
                    textView.setText("未验收");
                } else {
                    textView.setTextColor(getResources().getColor(R.color.text_color_4));
                    textView.setText("已验收");
                }
            }
        };
    }

    @Override
    public void initView() {
        super.initView();
        datas.addAll(GreenDaoManager.getInstance().getmDaoSession().getEProblemexistEntityDao()
                .queryBuilder().where(EProblemexistEntityDao.Properties.Projectguid.eq(SPUtils.get(context, "project_ys_guid", ""))
                        , EProblemexistEntityDao.Properties.Datastate.notEq("删除")).list());
        adapter.setData(datas);
        adapter.setEmptyDataView(R.layout.view_empty);
    }
}
